package com.lagou.edu.context;

import com.lagou.edu.utils.Assert;

/**
 * 应用程序上下文对象
 *
 * @author bwcx_jzy
 * @since 2021/10/21
 */
public class ApplicationContextUtil {

    /**
     * bean 工厂
     */
    private static volatile BeanFactory beanFactory;

    /**
     * 保存 factory
     *
     * @param beanFactory 工厂对象
     */
    public static void setBeanFactory(BeanFactory beanFactory) {
        ApplicationContextUtil.beanFactory = beanFactory;
    }

    /**
     * 获取当前 bean 工厂
     *
     * @return BeanFactory
     */
    public static BeanFactory getBeanFactory() {
        Assert.notNull(beanFactory, "还没有初始化上下文对象");
        return beanFactory;
    }
}
